package com.zhang.homework.countsort;

import java.util.Arrays;

/**
 * @author zhang
 * @time 2022/02/12 17:18:05
 */
public class Test {
    public static void countSort(int[] array,int max) {
        int[] sortArray = new int[max+1];
        for (int i = 0; i < array.length; i++) {
            sortArray[array[i]]++;
        }

        int k = 0;
        for (int i = 0; i < sortArray.length; i++) {
            while (sortArray[i]-- != 0) {
                array[k++] = i;
            }
        }
        System.out.println(Arrays.toString(array));
    }

    public static void main(String[] args) {
        int[] array = {1,4,23,67,89,13,45,67,2,123,5};
        countSort(array,123);
    }
}
